import random
import time

def make_random_list(n, low=0, high=100):
    nums = []
    for i in range(n):
        nums.append(random.randint(low, high))
    return nums

def find_kth(nums, k):
    nums.sort(reverse=True)
    return nums[k-1]

n=40000
k=100

nums = make_random_list(n, low=1, high=50)

print("随机生成的数组：", nums)
print("k =", k)

t1 = time.perf_counter()
ans = find_kth(nums, k)
t2 = time.perf_counter()

print("第k个最大的元素：", ans)
print("运行时间：", (t2 - t1) * 1000, "毫秒")
